package com.jic.market.impl.rest.realtimeprice.realTimePriceHandler;

import com.jic.market.common.enums.DeleteFlagEnum;
import com.jic.market.entity.GoodsPriceAndStock;
import com.jic.market.entity.PatchGrouponStockLmtEntity;
import com.jic.market.entity.PromotionEntity;
import com.jic.market.enums.FrontPromotionTypeEnum;
import com.jic.market.mapper.PatchGrouponStockLmtEntityMapper;
import com.jic.market.model.RealTimePriceContent;
import com.jic.market.response.rest.realtimeprice.RealTimePriceResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * description: PatchGrouponPriceHandler-一拼团
 * date: 2020/4/10 15:34
 * author: wangys
 * version: 1.0
 */
@Component
public class PatchGrouponPriceHandler implements BaseRealTimePriceHandler {
    @Autowired
    PatchGrouponStockLmtEntityMapper patchGrouponStockLmtEntityMapper;

    @Override
    public Integer handlerFrontType() {
        return FrontPromotionTypeEnum.BALANCE_CALCULATION.getCode();
    }

    @Override
    public String apply(PromotionEntity promotionEntity, GoodsPriceAndStock goodsPriceAndStock) {
        return null;
    }

    @Override
    public void accept(RealTimePriceContent realTimePriceContent) {
        PromotionEntity promotionEntity = realTimePriceContent.getPromotionEntity();
        RealTimePriceResponse realTimePriceResponse = realTimePriceContent.getRealTimePriceResponse();

        PatchGrouponStockLmtEntity param = new PatchGrouponStockLmtEntity();
        param.setRefPatchGrouponTheme(promotionEntity.getId());
        param.setMpCode(realTimePriceResponse.getThirdProductCode());
        param.setDeleteFlag(DeleteFlagEnum.UN_DELETE.getCode());
        PatchGrouponStockLmtEntity stockLmtEntity = patchGrouponStockLmtEntityMapper.query(param);
        realTimePriceResponse.setAvailablePrice(stockLmtEntity.getGrouponPrice() == null ? null : stockLmtEntity.getGrouponPrice().toString());
    }
}
